 /**
  * 添加成绩 获取学生平均成绩
  */
 class Student {
  constructor(name, scores = {}) {
    this.name = name;
    this.scores = scores;
  }
  setScore(subject, score) {
    this.scores[subject] = score;
  }
  getStudentAverage() {
    var total = 0;
    var length = 0;
    for (var subject in this.scores) {
      length += 1;
      total += this.scores[subject];
    }
    var average = (total / length).toFixed(2);
    return average;
  }
}
// 测试
var zhangsan = new Student("张三")
zhangsan.setScore("yuwen",99)
zhangsan.setScore("shuxue",100)
zhangsan.setScore("yinyu",90)
console.log(zhangsan.getStudentAverage())